package com.taomu.app.zongchouhuli.moudle.mine.adpter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.taomu.app.zongchouhuli.R;
import com.taomu.app.zongchouhuli.moudle.mine.entity.AccountBankEntity;
import com.taomu.app.zongchouhuli.moudle.mine.entity.IncomeDetailEnttiy;

import java.util.ArrayList;
import java.util.List;

public class IncomeDetailAdp extends RecyclerView.Adapter<IncomeDetailAdp.IncomeDetailHolder>{

    private List<IncomeDetailEnttiy> mData = new ArrayList<>();

    private Context mContext;

    private LayoutInflater inflater;

    public IncomeDetailAdp(Context mContext){
        this.mData = new ArrayList<>();
        this.inflater = LayoutInflater.from(mContext);
        this.mContext = mContext;
    }

    public void setData(java.util.List<IncomeDetailEnttiy> mData){
        this.mData.clear();
        this.mData.addAll(mData);
        notifyDataSetChanged();
    }

    public void addData(List<IncomeDetailEnttiy> mData){
        this.mData.addAll(mData);
        notifyDataSetChanged();
    }

    @Override
    public IncomeDetailHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_income_detail,parent,false);
        return new IncomeDetailHolder(view);
    }

    @Override
    public void onBindViewHolder(IncomeDetailHolder holder, int position) {
        final IncomeDetailEnttiy enttiy = mData.get(position);
        holder.update(enttiy);
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    class IncomeDetailHolder extends RecyclerView.ViewHolder{

        private TextView mKeysTv;

        private TextView mValueTv;

        public IncomeDetailHolder(View itemView) {
            super(itemView);
            mKeysTv = itemView.findViewById(R.id.item_incomdetail_key_tv);
            mValueTv = itemView.findViewById(R.id.item_incomdetail_value_tv);
        }

        public void update(IncomeDetailEnttiy enttiy){
            mKeysTv.setText(enttiy.getKey());
            mValueTv.setText(enttiy.getValue());
        }
    }
}
